package com.example.designpatterns.command.receiver;

/**
 * Door类 - 门，命令的接收者
 */
public class Door {
    private String location;
    private boolean isOpen;
    private boolean isLocked;
    
    /**
     * 创建一个门对象
     * @param location 门的位置
     */
    public Door(String location) {
        this.location = location;
        this.isOpen = false;
        this.isLocked = false;
        System.out.println(location + "的门已初始化");
    }
    
    /**
     * 打开门
     */
    public void open() {
        if (isLocked) {
            System.out.println(location + "的门已锁定，无法打开");
            return;
        }
        
        if (!isOpen) {
            isOpen = true;
            System.out.println(location + "的门已打开");
        } else {
            System.out.println(location + "的门已经是打开状态");
        }
    }
    
    /**
     * 关闭门
     */
    public void close() {
        if (isOpen) {
            isOpen = false;
            System.out.println(location + "的门已关闭");
        } else {
            System.out.println(location + "的门已经是关闭状态");
        }
    }
    
    /**
     * 锁门
     */
    public void lock() {
        if (isOpen) {
            System.out.println("请先关闭" + location + "的门再锁定");
            return;
        }
        
        if (!isLocked) {
            isLocked = true;
            System.out.println(location + "的门已锁定");
        } else {
            System.out.println(location + "的门已经是锁定状态");
        }
    }
    
    /**
     * 解锁门
     */
    public void unlock() {
        if (isLocked) {
            isLocked = false;
            System.out.println(location + "的门已解锁");
        } else {
            System.out.println(location + "的门已经是解锁状态");
        }
    }
    
    /**
     * 判断门是否开启
     * @return 门是否开启
     */
    public boolean isOpen() {
        return isOpen;
    }
    
    /**
     * 判断门是否锁定
     * @return 门是否锁定
     */
    public boolean isLocked() {
        return isLocked;
    }
    
    /**
     * 获取门的位置
     * @return 门的位置
     */
    public String getLocation() {
        return location;
    }
    
    /**
     * 获取门的状态信息
     * @return 状态描述
     */
    public String getStatus() {
        return location + "的门状态：" + (isOpen ? "开启" : "关闭") + 
               (!isOpen ? "，" + (isLocked ? "已锁定" : "未锁定") : "");
    }
} 